Skip to content

Conversation

@mjm2017
Copy link
Contributor

@mjm2017 mjm2017 commented Jul 1, 2019

Without freeing the DAC, the pin will continue to be configured as DAC. Which make it impossible to change it from AnalogOut to anything else.

Description

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

Release Notes

Without freeing the DAC, the pin will continue to be configured as DAC. Which make it impossible to change it from Analogout to anything else. 
Check this code that allow you to change the AnalogOut to DigitalOut

<<code>>
#include "mbed.h"

class myAnalog : public AnalogOut{
    public:

    myAnalog(PinName myname);
    ~myAnalog();
    
 PinName _myname;        
};
    
myAnalog::myAnalog(PinName myname):AnalogOut(myname),
                                   _myname(myname){
                                       ;
                                   
}
 myAnalog::~myAnalog(){
   analogout_free(&this->_dac);
 }

myAnalog *x=0;
DigitalOut *xx=0;
void do_something_analog() {
    x=new myAnalog(PA_4);
    double g=0.0;
    while(g<0.5){
    x->write(g);
    g=g+0.1;
    wait_ms(50);
    }
     if (x!=0){
      delete x;
      x=0;
    }
}

void do_something_digital() {
    xx=new DigitalOut(PA_4);
    for(int i=0;i<10;i++){
        *xx = 1;
       wait_ms(50);
        *xx = 0;
        wait_ms(50);
    }
   if (xx!=0){
      delete xx;
      xx=0;
    }
}

int main()
{
    printf("\nAnalog loop example\n");
    while(1) {
    do_something_digital();
    do_something_analog();    


 }
}

<</code>>
@ciarmcom
Copy link
Member

ciarmcom commented Jul 1, 2019

@mjm2017, thank you for your changes.
@ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested review from a team July 1, 2019 21:00
{
// Do nothing
// deinitialize the pin configuration totally. This should allow chaining the definition of the pin
analogout_free(&this->_dac);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the code style - see travis astyle failure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, But this is my first pull request. Please feel free to change my patch to whatever works for you by that I learn also to not make that mistake again.
thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this with Nucleo-L476RG.
The example sent with the patch .. I re-write it again:
#include "mbed.h"

class myAnalog : public AnalogOut{
public:

myAnalog(PinName myname);
~myAnalog();

PinName _myname;
};

myAnalog::myAnalog(PinName myname):AnalogOut(myname),
_myname(myname){
;

}
myAnalog::~myAnalog(){
analogout_free(&this->_dac);
}

myAnalog *x=0;
DigitalOut *xx=0;
void do_something_analog() {
x=new myAnalog(PA_4);
double g=0.0;
while(g<0.5){
x->write(g);
g=g+0.1;
wait_ms(50);
}
if (x!=0){
delete x;
x=0;
}
}

void do_something_digital() {
xx=new DigitalOut(PA_4);
for(int i=0;i<10;i++){
*xx = 1;
wait_ms(50);
*xx = 0;
wait_ms(50);
}
if (xx!=0){
delete xx;
xx=0;
}
}

int main()
{
printf("\nAnalog loop example\n");
while(1) {
do_something_digital();
do_something_analog();

}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please align the comment and the code line 143? Otherwise looks good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear Martin,
I cannot find this note as you mentioned (" Note: This is not currently used in the mbed-drivers")
Please write down for me the link to the file.
Notice that My change is only for NUCLEO-L476RG

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 2, 2019

This should be fixed in few other drivers as well. There are implications - free is either not implemented or if it is, we do not know what can happen once it is invoked in drivers. This change should have tests with it. How did you test it (what target do you use) ?

I would get this to the next minor release.

Remove also the comment: * Note: This is not currently used in the mbed-drivers note from analogout_api.c

Without freeing the DAC, the pin will continue to be configured as DAC. Which make it impossible to change it from AnalogOut to anything else.

Initialization for different use should take care of it in this use case (if you do AnalogIn on the pin, it should be reconfigured). Still though free should be invoked.

@0xc0170 0xc0170 requested a review from a team August 9, 2019 13:13
@0xc0170
Copy link
Contributor

0xc0170 commented Aug 9, 2019

Remove also the comment: * Note: This is not currently used in the mbed-drivers note from analogout_api.c

Still to do

Travis fails , please review astyle job

Copy link
Contributor Author

@mjm2017 mjm2017 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments fixed

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 23, 2019

astyle job still fails, please review.

@ARMmbed/mbed-os-hal Please review

Copy link
Member

@fkjagodzinski fkjagodzinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @0xc0170 already asked -- please update the HAL header:

* Note: This is not currently used in the mbed-drivers

/** Deinitialize the pin configuration totally.
*\ This should allow changing the definition of the pin
*/
analogout_free(&this->_dac);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
analogout_free(&this->_dac);
analogout_free(&_dac);

Private members are already marked with a _ prefix; no need to use this pointer here.

@mjm2017 mjm2017 requested review from 0xc0170 and removed request for a team September 16, 2019 19:53
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 18, 2019

@fkjagodzinski Please review

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Sep 20, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 merged commit 99c19b5 into ARMmbed:master Sep 20, 2019
@adbridge adbridge added release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 and removed release-version: 5.15.0-rc1 labels Oct 3, 2019
@0xc0170 0xc0170 added release-version: 5.15.0-rc1 and removed release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 labels Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants